import requests


class play_file():
    def __init__(self):
        self.s = requests.Session()  # 会话保存为实例变量
        url = 'http://localhost:63342/Python%20Project/InterfaceTest/day04/upload.html'  # 更改为支持文件上传的 URL

        # 使用 with 语句打开文件，确保自动关闭
        with open('D:/image/sssd.jpg', 'rb') as f:
            data = {
                'name': (None, 'ls'),
                'age': (None, '24'),
                'sex': (None, 'man'),
                'good.jpg': ('123.jpg', f, 'image')  # 上传文件
            }
            response = self.s.post(url, files=data)
            print(response.status_code, response.content)  # 打印响应信息


if __name__ == '__main__':
    play_file()  # 直接实例化类，无需显式调用 __init__()
